﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Homework.Domain.Table;
using Homework.Domain.Dto;
using LY.OAWeb.Repository.IRepository;

namespace Homework.Service
{
    public class UserService : IUserService
    {
        IProductRepository _ProductRepository;

        public UserService(IProductRepository productRepository)
        {
            _ProductRepository = productRepository;
        }

        public PageList<ProductDto> Show(int pageIndex = 1, int pageSize = 2)
        {
            var list = from s in _ProductRepository.GetProducts()
                       select new ProductDto
                       {
                           ProductId = s.ProductId,
                           ProductName = s.ProductName,
                           ProductNumber = s.ProductNumber,
                       };
            var total = list.Count();
            var data = list.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return new PageList<ProductDto>
            {
                data = data,
                total = total
            };
        }
    }
}
